#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''eof
name:一度关联方黑名单风险
code:RP1DuBlacklistRisk
tableName:
columnName:
groups:关联方
dependencies:EG_BBD
type:常用指标
dataSourceType:在线指标
description:
eof'''

import sys

reload(sys)
sys.setdefaultencoding('utf-8')


def float_check(num):
    try:
        float(num)
        return True
    except:
        return False


def int_check(num):
    try:
        int(num)
        return True
    except:
        return False


def RP1DuBlacklistRisk():
    null_type_list = ['', None, 'None', 'null', 'Null', 'NULL', '/', ' ']
    try:
        interface_data = EG_BBD["srcData"][0]["OFF_RELATED_INDEX"]
        if interface_data["status"] != 200:
            return u'缺失值'
        index_codes = interface_data["data"][0]["indexCodes"]
        result_list = []
        fac1 = str(index_codes.get("47B"))
        fac2 = str(index_codes.get("48B"))
        fac3 = str(index_codes.get("49B"))
        fac4 = str(index_codes.get("50B"))
        if fac1 not in null_type_list and int_check(fac1) and int(fac1) != 99999:
            result_list.append(int(fac1))
        if fac2 not in null_type_list and int_check(fac2) and int(fac2) != 99999:
            result_list.append(int(fac2))
        if fac3 not in null_type_list and int_check(fac3) and int(fac3) != 99999:
            result_list.append(int(fac3))
        if fac4 not in null_type_list and float_check(fac4) and (99998 >= float(fac4) or float(fac4) > 100000):
            result_list.append(float(fac4))
        if len(result_list) >= 1:
            return sum(result_list)
        else:
            return u'缺失值'
    except:
        return u'缺失值'


result = RP1DuBlacklistRisk()
